<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
  
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <script type="text/javascript">
  	function test(){
		var image = document.getElementsByTagName("img")[0];
		var myDate = new Date();
		image.src = "image.jsp?time="+myDate.getTime();
		alert(image.src);
		

  	 }
  	function  CheckUsers(){
  		var username=document.getElementById("name").value;
  		var password=document.getElementById("password").value;
  		var code=document.getElementById("yanz").value;
  	    if(username.length<=0){
  			alert("用户名不为空");
  			return false;
  		}
  		
  		if(password.length<=0){
  			alert("密码不为空");
  			return false;
  		}
  		if(code.length<=0){
  			alert("验证码不为空");
  			return false;
  		}
  	return true;	
  	}
  </script>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<%
	 String username=(String)session.getAttribute("users");
     String pws=(String)session.getAttribute("pws");
     String rand = (String)session.getAttribute("rand");
     String input = request.getParameter("yanz");
     String loginame=request.getParameter("name");
     String loginpwd=request.getParameter("password");
     
     
   			if (input!= null && loginame!= null && loginpwd!= null) {
   				
   				
   				
		  session.setAttribute("usere", loginame);
		   session.setAttribute("pwse", loginpwd); 
		if (loginame.equals(username) && loginpwd.equals(pws) && rand.equals(input)) {
			
			response.sendRedirect("main.jsp");
		} else if (loginame.equals(username) && loginpwd.equals(pws) && !rand.equals(input)) {
			out.print("<script> alert('验证码不正确，请重新输入')</script>");

		} else if (!loginame.equals(username) && loginpwd.equals(pws) && rand.equals(input)) {
			out.print("<script>alert('登录账号不正确，请重新输入')</script>");

		} else if (loginame.equals(username) && !loginpwd.equals(pws) && rand.equals(input)) {
			out.print("<script>alert('密码不正确，请重新输入')</script>");

		  }  

	}
%>  

<title>用户登录</title>
</head>
<body>
<form method=post  onsubmit="return CheckUsers()">
<div class="regist" style="text-align: center; ">
登录账号： <input type="text"  id="name" name="name" style="width: 180px; height: 25px;margin-left: -15px "/><br><br>
密        码： <input type="password" id="password" name="password" style="width: 180px; height: 25px; "/><br><br>
<span style="margin-right: 40px">验证码：</span> <span style="margin-right: 30px"><img alt="" onclick="test();" src="ValidateImg.jsp" ></span><br><br>    
       <input type="text" id="yanz"  name="yanz" style="width: 180px; height: 25px; margin-left: 50px"/><br><br>
<input type="submit" value="登录"
				style="width: 100px; height: 40px; background: #00FFFF; font-size: 18px;">
</div>
</form>
</body>
</html>